package org.example.service;

import java.util.Scanner;

public class Work4 {
    /**
     * 输入一个正则表达式，验证有效的网络Ipv4地址。
     */
    public void verify() {
        boolean tr = false;
        System.out.println("请输入Ipv4地址");
        Scanner sc = new Scanner(System.in);
        String verify = sc.next();
        String[] ip = verify.split("[.]");

        if (ip.length == 4) {
            for (String v : ip) {
                if (v.matches("([0-9]|[0-1]?[0-9][0-9]|25[0-5][0-5]|2[0-4][0-9])")) {
                    tr = true;
                }else {
                    tr = false;
                    break;
                }
            }
        }
        if (tr) {
            System.out.println("正确");
        } else {
            System.err.println("错误");
        }
    }

    public static void main(String[] args) {
        Work4 work4 = new Work4();
        work4.verify();
    }
}
